************************************************************************
/*			Filename: 2021-09-17 Code for Response to Missing Decisions.do */
/*			Purpose: analysis of document to docket completeness for 2015 */
/*			Author: Jason Rantanen		*/
/*			Date created: 2021-07-15 */
/*			Input files: docket dataset, document dataset, coding of dockets with missing decisions */
************************************************************************

//Updated on 2021-08-10, 2021-09-17

//NOTE: You must first run the Code for conducting full analysis of missing decisions over all times.do

/* To make pretty tables that export to Word, download this program, and use command "asdoc" tab */
ssc install asdoc

//CHANGE THE BELOW DIRECTORY TO THE LOCATION OF THE DATA FILES

cd "/Users/jrantanen/Documents/Scholarship/2021 Response to Missing Decisions/Final Data and Code/"

//Make sure to change directory to the directory where the data files are located. 

use "2021-08-06 CAFC Dockets.dta", clear

keep if Year_Appeal_Filed==2015

save "Appeal Dockets for year 2015 merge.dta", replace

use "Appeal Dockets for year 2015 merge.dta", clear

merge 1:1 Appeal_Dockets using "appeals filed with terminating documents in Compendium"

tab Year_Appeal_Filed _merge

keep if Year_Appeal_Filed==2015

//Next misc appeal docket numbers are dropped.
split(Appeal_Dockets), parse(-) gen(temp)
destring(temp2), replace
drop if temp2<1000
drop temp*

//This provides us with a set of all appeals docketed in 2015 that indicates whether there is an Opinion, a Rule 36, or an Order in the dataset.  

replace docType="Missing" if docType==""
replace DataSource="Missing" if DataSource==""
label var DataSource "Source of document"

tab docType, missing
tab docType DataSource, missing

asdoc tab docType DataSource, missing label font(Times New Roman) fs(12) save(tables.doc) replace title(Dockets with documents in Compendium)

drop _merge

merge 1:1 PACER_Appeal_Docket using "/Users/jrantanen/Documents/Scholarship/2021 Response to Missing Decisions/Missing decisions - document collection/2021-07-29 Missing termination documents - (Final Set).dta", update

save "Initial comparison of 2015 appeal dockets to documents", replace

label var TypeAppealTermination "Type of Terminating Document for missing terminations"

rename ReasonAppealTerminationDocket ReasonAppealTerminated
label var ReasonAppealTerminated "Reason appeal was terminated"

asdoc tab TypeAppealTermination if DataSource!="CAFC Website", missing label font(Times New Roman) fs(12) save(tables.doc) append title(Terminating document type for dockets without a document on the CAFC website)

asdoc tab ReasonAppealTerminated if DataSource!="CAFC Website" & TypeAppealTermination=="Dismissal", missing label font(Times New Roman) fs(12) save(tables.doc) append title(Reason for termination for dockets that were dismissed)

gen MissingDecisions=1 if DataSource!="CAFC website" & (ReasonAppealTerminated=="Dismissal" | ReasonAppealTerminated=="Remand" | ReasonAppealTerminated=="Transfer" | ReasonAppealTerminated=="Merits Order") 
tab MissingDecisions
duplicates report Full_Appeal_Dockets1 if MissingDecisions==1
duplicates report Full_Appeal_Dockets1 if ReasonAppealTerminated =="Merits Order"


